Ext.define('AM.view.MyCreatJobView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.myCreatJobView',
		store : 'MyCreatJobStore',
		columnLines:true,
		plugins: [{
            ptype: 'rowexpander',
            rowBodyTpl : new Ext.XTemplate(
                '<p><b>要求:</b> {jobRequirement}</p>'
            )
        }],
          viewConfig: {  
            forceFit:true,//当行大小变化时始终填充满  
            enableRowBody:true,//可以用两行tr来表示一行数据  
            showPreview:true,//初始显示预览效果,这个是自定义的属性  
            getRowClass : function(record,rowIndex,rowParams,store){  
        	var ni=record.get('planCompleteDate');
        	var hao=new Date();
        	if((ni-hao)/1000/60/60<24){
        		  cls = 'red_row';
        	}
        	if((ni-hao)/1000/60/60>24){
        		  cls = 'red_row';
        	}
        	return cls;
        	}
        },
		columns: [
			        { text: '序号', width:50,align:'center', xtype: 'rownumberer'},
			        { text: '任务性质',  dataIndex: 'tastproperty',  width:80,align:'center',renderer: function(value){
								 if (value === 0) {
										 return '创新性工作';
								 }	
								 if (value === 1) {
									 return '<font color=blue></font><span style="color:red;">一级</span>'; 
								 }
								 if (value ===2) {
								 	return '<font color=blue></font><span style="color:red;">二级</span>'
								 }
								 if (value ===3) {
								 	return '<font color=blue></font><span style="color:yellow;">三级</span>'	
								 }	
								 if (value ===4) {
								 	return '<font color=blue></font><span style="color:green;">四级</span>'	
								 }					 
						 }
			        },
			        { text: '名称', dataIndex: 'name', width:90,align:'center'},
			        { text: '步骤', dataIndex: 'step', width:50,align:'center'},
			        { text: '所属项目', dataIndex:'job.name', width:90,align:'center'},
			        { text: '开始时间', dataIndex: 'startdate', width:100,align:'center',xtype: 'datecolumn',   format:'Y-m-d'},
			        { text: '计划完成时间',  dataIndex: 'planCompleteDate',  width:100,align:'center',xtype: 'datecolumn',   format:'Y-m-d' },
//			        { text: '得分',dataIndex: 'core', width:50,align:'center' },
			        { text: '状态', dataIndex: 'state',  width:80,align:'center',renderer: function(value){
								 if (value === 2) {
										 return '<span style="color:green;">办理中</span>';
								 }if (value ===1) {
										  return '<span style="color:purple;">未办理</span>'; 
								 }if (value === 3) {
										 return '<span style="color:red;">结束</span>';
								 }	
						}					 
			        },
			        { text: '要求', dataIndex: 'jobRequirement', width:150,align:'center'},
			        { text: '操作', dataIndex: 'id',width:220,align:'center',renderer : function(data, cell, record, rowIndex,columnIndex){			        	
			        	    var resultStr = "<div class='controlBtn'>" +     
                            "<a href='javascript:void("+record.get('id')+");'class='alarm_detail'onclick='banLiCeatJob("+record.get('id')+")'>办理任务</a>&nbsp;&nbsp;&nbsp;&nbsp;" +     
                            "<a href='javascript:void("+record.get('id')+");' class='alarm_detail'onclick='wanchengCreatJob("+record.get('id')+")'>完成任务</a>&nbsp;&nbsp;&nbsp;&nbsp;"+ 
                             "<a href='javascript:void("+record.get('id')+");'class='alarm_detail'onclick='loadfujian("+record.get('id')+")'>下载附件</a>&nbsp;&nbsp;&nbsp;&nbsp;"   
                            "</div>";     
         					return resultStr;  
			       		  }
         	    	}
			     ]

})

//下载附件
function loadfujian(id){
	    var jobid=id;
	 	Ext.Ajax.request({
				url : 'jobDetail_download',
				success : function() {
						 window.location.href ="download?id="+id+"";
				},
				failure : function() {
					Ext.MessageBox.alert("提示", "无附件可以下载！");
				},
				params : {
						jobId:jobid	
					}
		});		
	
	
	
}
 function banLiCeatJob(id){
	   	  	Ext.Ajax.request({
					url : 'jobDetail_banli',
					success : function() {
								var myform1= new Ext.form.Panel({
										        layout : "form",
										        labelWidth : 200,
										        items: [{
												        layout : "column",
												        border : false,
												        	items: [{
														        	columnWidth :.80,
																	layout : "form",
																	border : false,
																	labelWidth : 30,
														   			items: [{
														   				    xtype : "textarea",
														   				    fieldLabel: '回复内容',
														   				    labelAlign :"right",
																            name: 'huifu',
																            width:200
																        }]		        	
													        	}]
										        	 }]
							 	 })
								var win = new Ext.Window({
										title : "添加回复",
										width : 500,
										height : 200,
										frame:true,
										layout:'fit',
									    items :[myform1],
										buttons : [
												  {text : "确定",
														handler : function() {
															win.getComponent(0).getForm().submit({
																		    url : 'jobDetail_huifu',
																		    success : function() {
																			Ext.Msg.alert('提示', '回复成功');
																			win.close();
																		},
																		failure : function() {
																			Ext.Msg.alert('错误', '回复失败');
																		},
																		waitMsg : "请稍后，正在保存。。。。",
																	params : {
																				id:id	
																				}
																});
														}
													}, {
														text : "重置",
														handler : function() {
															win.getComponent(0).getForm().reset();
														}
													}, {
														text : "取消",
														handler : function() {
																			win.close();
																		
														}
											}]
						 	}).show();
						
					 myJobView=Ext.create('AM.view.MyCreatJobView');
					 myJobView.getStore().reload();							 
				},
				failure : function() {
					Ext.MessageBox.alert("提示", "项目正在办理中！");
				},
				params : {
						id:id	
					}
		});		
   
 }
   //完成工作
  function wanchengCreatJob(id){
   	  	Ext.Ajax.request({
				url : 'jobDetail_wancheng',
				success : function() {
					 myJobView=Ext.create('AM.view.MyCreatJobView');
					 myJobView.getStore().reload();						 
				},
				failure : function() {
					Ext.MessageBox.alert("提示", "项目还未办理！");
				},
				params : {
						id:id	
					}
		});	 
 	
 }
